# -*- coding: utf-8 -*-#

# -------------------------------------------------------------------------------
# Name:         dataset
# Description:
# Author:       zx
# Date:         2020/9/28
# -------------------------------------------------------------------------------
import tensorflow as tf
import numpy as np


def add(x):
    return x * 2


dataset = tf.data.Dataset.from_tensor_slices(np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]))
dataset = dataset.map(add)  # 2.0, 3.0, 4.0, 5.0, 6.0
dataset = dataset.shuffle(buffer_size=6)
dataset = dataset.batch(2)
dataset = dataset.repeat(1)

iterator = dataset.make_one_shot_iterator()
one_element = iterator.get_next()
with tf.Session() as sess:
    try:
        while True:
            print(sess.run(one_element))
    except tf.errors.OutOfRangeError:
        print("end!")
